<?php
include("receivemail.class.php");
include("conn.php");
header ('Content-type: text/html; charset=iso-8859-1');
// Creating a object of reciveMail Class
$obj= new receiveMail('oneview@adapare.com','C4mbio4d4p4r3','oneview@adapare.com','pop.gmail.com','pop3','995',true);
$obj->connect();         //If connection fails give error message and exit
// Get Total Number of Unread Email in mail box
$tot=$obj->getTotalMails(); //Total Mails in Inbox Return integer value

//echo "Total Mails:: $tot<br>";

	for($i=$tot;$i>0;$i--)
	{
		$head=$obj->getHeaders($i);  // Get Header Info Return Array Of Headers **Array Keys are (subject,to,toOth,toNameOth,from,fromName)
		
		$consulta="insert into correo(subject,de,msg,para,fromname) values('".$head['subject']."','".$head['from']."','".$obj->getBody($i)."','".$head['to']."','".$head['fromName']."')";
		mysql_query($consulta,$conexion);
		
		/*echo "Subjects :: ".$head['subject']."<br>";
		echo "TO :: ".$head['to']."<br>";
		echo "To Other :: ".$head['toOth']."<br>";
		echo "ToName Other :: ".$head['toNameOth']."<br>";
		echo "From :: ".$head['from']."<br>";
		echo "FromName :: ".$head['fromName']."<br>";
		echo "<br><br>";
		echo "<br>*******************************************************************************************<BR>";
		echo $obj->getBody($i);  // Get Body Of Mail number Return String Get Mail id in interger
		*/
		/*
		$str=$obj->GetAttach($i,"./"); // Get attached File from Mail Return name of file in comma separated string  args. (mailid, Path to store file)
		$ar=explode(",",$str);
		foreach($ar as $key=>$value)
			echo ($value=="")?"":"Atteched File :: ".$value."<br>";
			*/
		//echo "<br>------------------------------------------------------------------------------------------<BR>";
		//$obj->deleteMails($i); // Delete Mail from Mail box
	}
$obj->close_mailbox();   //Close Mail Box

		$consulta="SELECT subject,de,msg,para,fromname FROM correo";
		$resultado=mysql_query($consulta,$conexion);
		if(mysql_num_rows($resultado)>0)
		{
			?>
			<table border="1">
			<tr>
				<td>Titulo</td>
				<td>De</td>
				<td>Mensaje</td>
				<td>Para</td>
				<td>Nombre</td>
			</tr>
			<?php
			for($a=0;$a<mysql_num_rows($resultado);$a++)
			{
				$res=mysql_fetch_array($resultado);
				?>
			 <tr>
				<td><?php echo $res['subject']?></td>
				<td><?php echo $res['de']?></td>
				<td><?php echo $res['msg']?></td>
				<td><?php echo $res['para']?></td>
				<td><?php echo $res['fromname']?></td>
			</tr>
				
				<?php
			}
		
		
?>
		</table>
        <?php
		}
		?>